package com.airbnb.epoxy;

import com.airbnb.epoxy.models.ButtonBindingModel_;
import com.airbnb.epoxy.models.CarouselModelGroup;
import com.airbnb.epoxy.models.ImageBindingModel_;
import com.airbnb.epoxy.models.TextBindingModel_;
import com.airbnb.epoxy.views.HeaderViewModel_;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ShapeElement;
import ohos.app.Context;

import java.util.ArrayList;
import java.util.List;

public class SampleController extends TypedEpoxyController<List<CarouselData>> {
  Context context;
  public interface AdapterCallbacks {
    void onAddCarouselClicked();
    void onClearCarouselsClicked();
    void onShuffleCarouselsClicked();
    void onChangeAllColorsClicked();
    void onAddColorToCarouselClicked(CarouselData carousel);
    void onClearCarouselClicked(CarouselData carousel);
    void onShuffleCarouselColorsClicked(CarouselData carousel);
    void onChangeCarouselColorsClicked(CarouselData carousel);
    void onColorClicked(CarouselData carousel, int colorPosition);
  }

//  @AutoModel
//  HeaderViewModel_ header;


//  @AutoModel ButtonBindingModel_ addButton;
//  @AutoModel ButtonBindingModel_ clearButton;
//  @AutoModel ButtonBindingModel_ shuffleButton;
//  @AutoModel ButtonBindingModel_ changeColorsButton;
//  @AutoModel TextBindingModel_ text;


  private final AdapterCallbacks callbacks;
//  private final RecycledViewPool recycledViewPool;

  public SampleController(AdapterCallbacks callbacks/*, RecycledViewPool recycledViewPool*/ ,Context context) {
    this.callbacks = callbacks;
    this.context = context;
//    this.recycledViewPool = recycledViewPool;
    setDebugLoggingEnabled(true);
  }

  @Override
  protected void buildModels(List<CarouselData> carousels) {

   /* header
            .title(context.getString(ResourceTable.String_epoxy))
            .caption(context.getString(ResourceTable.String_header_subtitle));*/
    // "addTo" is not needed since implicit adding is enabled
    // (https://github.com/airbnb/epoxy/wiki/Epoxy-Controller#implicit-adding)
//

    List<ImageBindingModel_> imageList = new ArrayList<>();

    String[] countryArray = context.getStringArray(ResourceTable.Strarray_countries);
    long id = 54542;
    for (int pos = 0; pos <= countryArray.length - 1; pos++) {
      ImageBindingModel_ image = new ImageBindingModel_();


      image.id(id+pos).imageRes(ResourceTable.Media_icon).addTo(this);
      imageList.add(image);
    }

    /*List<TextBindingModel_> textList = new ArrayList<>();
    String[] countryArray = context.getStringArray(ResourceTable.Strarray_countries);
    long id = 54542;
    for (int pos = 0; pos <= countryArray.length - 1; pos++) {
      TextBindingModel_ text = new TextBindingModel_();
      text.id(id+pos).textRes(countryArray[pos]).addTo(this);
      textList.add(text);
    }*/


//    text.textRes(ResourceTable.String_app_name).addIf(true, this);
    /*addButton
        .textRes(ResourceTable.String_button_add)
            .clickListener((model, parentView, clickedView, position) -> callbacks.onAddCarouselClicked())
            .addIf(carousels.size() > 0, this);
//
    clearButton
        .textRes(ResourceTable.String_button_clear)
        .clickListener(v -> callbacks.onClearCarouselsClicked())
        .addIf(carousels.size() > 0, this);
//
    shuffleButton
        .textRes(ResourceTable.String_button_shuffle)
        .clickListener(v -> callbacks.onShuffleCarouselsClicked())
        .addIf(carousels.size() > 0, this);

    changeColorsButton
        .textRes(ResourceTable.String_button_change)
        .clickListener(v -> callbacks.onChangeAllColorsClicked())
        .addIf(carousels.size() > 0, this);*/


    /*for (int i = 0; i < carousels.size(); i++) {
      CarouselData carousel = carousels.get(i);
      add(new CarouselModelGroup(carousel, callbacks));
    }*/
  }

  @Override
  protected void onExceptionSwallowed(RuntimeException exception) {
    // Best practice is to throw in debug so you are aware of any issues that Epoxy notices.
    // Otherwise Epoxy does its best to swallow these exceptions and continue gracefully
    throw exception;
  }
}
